package com.cyjt.operation.adapter;

import java.util.List;

import com.cyjt.operation.R;
import com.cyjt.operation.bean.ShiftRecord;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * 排班查询listView的适配器
 * 
 * @author LTP
 *
 */
public class ShiftRecordAdapter extends ArrayAdapter<ShiftRecord> {
	private int resourceId;

	public ShiftRecordAdapter(Context context, int textViewresourceId, List<ShiftRecord> objects) {
		super(context, textViewresourceId, objects);
		resourceId = textViewresourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ShiftRecord shiftRecord = getItem(position);// 获取当前的ShiftRecord实例
		ViewHolder mViewHolder;
		if (convertView == null) {
			convertView = LayoutInflater.from(getContext()).inflate(resourceId, null);
			mViewHolder = new ViewHolder();
			mViewHolder.shiftRecordId = (TextView) convertView.findViewById(R.id.textView_id_for_shift_record);
			mViewHolder.shiftRecordAreaId = (TextView) convertView.findViewById(R.id.textView_areaid_for_shift_record);
			mViewHolder.shiftRecordDuringTime = (TextView) convertView
					.findViewById(R.id.textView_duringtime_for_shift_record);
			mViewHolder.shiftRecordName = (TextView) convertView.findViewById(R.id.textView_name_for_shift_record);
			mViewHolder.shiftRecordCode = (TextView) convertView.findViewById(R.id.textView_code_for_shift_record);
			convertView.setTag(mViewHolder);// 将mViewHolder存储在convertView中
		} else {
			mViewHolder = (ViewHolder) convertView.getTag();// 重新获取mViewHolder
		}
		mViewHolder.shiftRecordId.setText(shiftRecord.getId() + "");
		mViewHolder.shiftRecordAreaId.setText(shiftRecord.getAreaId());
		mViewHolder.shiftRecordDuringTime.setText(shiftRecord.getDuringtime());
		mViewHolder.shiftRecordName.setText(shiftRecord.getName());
		mViewHolder.shiftRecordCode.setText(shiftRecord.getCode());
		return convertView;
	}

	class ViewHolder {
		TextView shiftRecordId;
		TextView shiftRecordAreaId;
		TextView shiftRecordDuringTime;
		TextView shiftRecordName;
		TextView shiftRecordCode;
	}
}
